var mongoose=require('mongoose');
var Post=mongoose.model('Post',{
    title:String,
    authors:[String],
    comments:[
        {
            content:String,
            like:Number
        }
    ],
    slice:Array,
    emails:[String],
    todo:[String],
    author:Object,
    read:Number
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');

var title='post8';
Post.update({title:title},{
    todo:[0,1,2,3,4,5],
    author:{name:'Tom',age:20},
    read:100
},{upsert:true},(err,r)=>{
    console.log('Update:',err,r);

    Post.find({title:title},(e,r)=>{
        console.log('Find:\n',e,r);


        Post.update({title:title},{$unset:{todo:'',author:0,read:null}},(e,r)=>{
            console.log('unset:',e,r);

            Post.find({title:title},(e,r)=>{
                console.log('Find:\n',e,r);
                process.exit(1);
            });
        });
    });

});


/*
* $unset:{field:key}
* key可取任意值，一般为1
*
* field为数组时，清空数组
* field为对象时，删除字段名和值
* field为基本值时，删除字段名和值
* */